package com.dpwgc.alisalog.monitor.base;

import com.dpwgc.alisalog.common.constant.Code;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(value = "统一返回模板-DTO")
public class ApiBase<T> {

    @ApiModelProperty(value = "响应代码")
    protected Integer code;

    @ApiModelProperty(value = "响应信息")
    protected String message;

    @ApiModelProperty(value = "响应数据")
    protected T data;

    public Integer getCode() {
        return this.code;
    }

    public ApiBase<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return this.message;
    }

    public ApiBase<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public ApiBase() {
    }

    public T getData() {
        return this.data;
    }

    public ApiBase<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <T> ApiBase<T> getSuccessResult(T v) {
        ApiBase<T> apiBase = new ApiBase();
        apiBase.setCode(Code.SUCCESS);
        apiBase.setMessage("success");
        apiBase.setData(v);
        return apiBase;
    }

    public static <T> ApiBase<T> getFailureResult(String msg) {
        ApiBase<T> apiBase = new ApiBase();
        apiBase.setCode(Code.ERROR);
        apiBase.setMessage(msg);
        return apiBase;
    }
}
